package cn.tedu.sp04.service;

import cn.tedu.sp01.pojo.Order;
import cn.tedu.sp01.service.OrderService;
import cn.tedu.sp04.feign.ItemFeignClient;
import cn.tedu.sp04.feign.UserFeignClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class OrderServiceImpl implements OrderService {


    @Autowired
    private ItemFeignClient itemFeignClient;

    @Autowired
    private UserFeignClient userFeignClient;

    @Override
    public Order getOrder(String orderId) {
        Order order = new Order();
        order.setId(orderId);
        // todo 后续调用商品接口
//        order.setItems("商品列表");
        order.setItems(itemFeignClient.getItems(orderId).getData());
        // TODO 后续调用用户接口
//        order.setUser("用户信息");
        order.setUser(userFeignClient.getUser(12345).getData());

        return order;
    }

    @Override
    public void addOrder(Order order) {
        itemFeignClient.decreaseNumber(order.getItems());
        userFeignClient.addScore(111, 80);
        log.info("添加订单："+order);
    }
}
